<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>批量转舍</title>
		<link href="css/new_file.css" rel="stylesheet" type="text/css">
		<link href="css/mui.min.css" rel="stylesheet" type="text/css">

		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<link href="css/mui.picker.css" rel="stylesheet" />
		<link href="css/mui.poppicker.css" rel="stylesheet" />

		<script src="js/mui.min.js"></script>

		<script charset="UTF-8" src="js/config.js"></script>
		<script charset="UTF-8" src="js/testActivityName.js"></script>
		<script charset="UTF-8" src="js/core.js"></script>
		<script charset="UTF-8" src="js/cipher-core.js"></script>
		<script charset="UTF-8" src="js/tripledes.js"></script>
		<script charset="UTF-8" src="js/mode-ecb.js"></script>
		<script src="js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="js/zepto.min.js"></script>
		<script type="text/javascript" src="js/spin.min.js"></script>

		<script src="js/jquery.qrcode.min.js"></script>
		<script src="js/qrcode.js"></script>
		<script src="js/jquery.qrcode.js"></script>

		<script src="js/mui.picker.js"></script>
		<script src="js/mui.poppicker.js"></script>
		<script src="js/city.data.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/city.data-3.js" type="text/javascript" charset="utf-8"></script>

	</head>

	<body>
		<div class="head-zhjf">
			<img src="images/fanhui@3x.png" class="ryjk-tx" onclick="fanhuizhuan()">
			<div>批量转舍</div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">转出牛舍</div>
			</div>
			<div class="moban-lb-r" onclick="outCowshed()">
				<p class="ziduan-mb" id="outCowshedID">请选择</p>
			</div>
			<div class="clear"></div>
		</div>

		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">转入牛舍</div>
			</div>
			<div class="moban-lb-r" onclick="enterCowshed()">
				<p class="ziduan-mb" id="enterCowshedID">请选择</p>
			</div>
			<div class="clear"></div>
		</div>

		<div class="div-p-zs">请选择奶牛</div>

		<div style="padding-bottom: 90px;">
			<form name="form1" action="test.jsp" method="post" onsubmit="return checkData();">
				<div class="moban-lb ">
					<input class="duoxuan" type="checkbox" name="Bike1" value="0" onClick="checkAllBox(this);">
					<div class="qx">全选</div>
				</div>
				<div id="cowNumber"></div>
				<!--<div class="plzs-div" >
				<div class="ns-left"><input class="duoxuan" type="checkbox" name="Bike"></div>
				<div class="ns-right">
					<div class="ns-right-a">NB0020</div>
				</div>
				<div class="clear"></div>
			</div>-->
			</form>
		</div>
		<div class="tijiao" style="background: #FFFFFF; padding: 5px 0px;bottom: 0px;border-top:1px solid #eeeeee ;">
			<button type="button" class="tijiao-btn" onclick="SubBut()">提交</button>
		</div>
		<script>
			function fanhuizhuan(){
      		window.location = "4.转舍1.html";
      	}
			var wholeArr = new Array();
			var toHouseID;
			var fromHouseID;
			var toHouseName;
			//复选框事件
			function checkAllBox(obj) {
				var answer = document.getElementsByName("Bike");
				if(obj.checked == true) {
					for(var i = 0; i < answer.length; i++) {
						answer[i].checked = true;
					}
				} else {
					for(var i = 0; i < answer.length; i++) {
						answer[i].checked = false;
					}
				}
			}
			function checkData() {
				var answer = document.getElementsByName("Bike");
				var flag = false;
				for(var i = 0; i < income.length; i++) {
					if(income[i].checked == true) {
						flag = true;
						break;
					}
				}
				if(!flag) {
				}
				return flag;
			}
			function SubBut() {
				
				
				obj = document.getElementsByName("Bike");
				check_val = [];
				for(k in obj) {
					if(obj[k].checked)
						check_val.push(obj[k].value);
				}
				var arr = new Array();
				for (var i=0;i<check_val.length;i++) {
					arr.push(wholeArr[check_val[i]]["cowID"]);
				}
				if (fromHouseID == undefined) {
					mui.toast("请选择转出的牛舍名称");
					return;
				} else if (toHouseID == undefined){
					mui.toast("请选择转入的牛舍名称");
					return;
				}else if (arr.length == 0) {
					mui.toast("请选择转舍的奶牛编号");
					return;
				}
				
				console.log(arr);
				console.log(fromHouseID);
				console.log(toHouseID);
				
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.cowID = arr;
				map.fromHouseID = fromHouseID;
				map.toHouseID = toHouseID;
				map.toHouseName = toHouseName;
				map.phoneType = "android";
				map.language = "zh";
				var jsonStr = JSON.stringify(map);
				console.log(jsonStr);
				showDialog();
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "transfer",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str11 = decryptByDESModeEBC(data["result"]); //解密
						var params = str11.replace(/\+/g, " "); //去掉字符串里的+号
						var str12 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str12); //转JSON字符串
						var aa1 = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa1 + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							console.log(bb)
							window.location = "功能列表.html";
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();　　　　　
							mui.alert("网络请求超时...");　　　　
						}　　
					}
				});
			
				
				
			}

			function outCowshed() {
				localStorage.setItem('outEnterCowshed', JSON.stringify(1));
				shuju();
			}

			function enterCowshed() {
				localStorage.setItem('outEnterCowshed', JSON.stringify(2));
				shuju();
			}

			function shuju() {
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.phoneType = "android";
				map.language = "zh";
				var jsonStr = JSON.stringify(map);
				console.log(jsonStr);
				showDialog();
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "houseList",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str11 = decryptByDESModeEBC(data["result"]); //解密
						var params = str11.replace(/\+/g, " "); //去掉字符串里的+号
						var str12 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str12); //转JSON字符串
						var aa1 = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa1 + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							var ChooseACowshedArr = new Array();
							for(var i = 0; i < bb.data.length; i++) {
								var Arr = {
									"value": "",
									"text": ""
								};
								ChooseACowshedArr.push(Arr);
								ChooseACowshedArr[i]["value"] = bb.data[i]["houseID"];
								ChooseACowshedArr[i]["text"] = bb.data[i]["houseName"];
							}
							var outEnterCowshed = JSON.parse(localStorage.getItem('outEnterCowshed'));
							if(outEnterCowshed == 2) {
								for(var i = 0; i < ChooseACowshedArr.length; i++) {
									if(document.getElementById("outCowshedID").innerHTML == ChooseACowshedArr[i]["text"]) {
										ChooseACowshedArr.splice(i, 1);
									}
								}
							}
							if(outEnterCowshed == 1) {
								for(var i = 0; i < ChooseACowshedArr.length; i++) {
									if(document.getElementById("enterCowshedID").innerHTML == ChooseACowshedArr[i]["text"]) {
										ChooseACowshedArr.splice(i, 1);
									}
								}
							}
							console.log(ChooseACowshedArr);
							(function($, doc) {
								$.init();
								$.ready(function() {
									var _getParam = function(obj, param) {
										return obj[param] || '';
									};
									//普通示例
									var userPicker = new $.PopPicker();
									userPicker.setData(ChooseACowshedArr);
									userPicker.show(function(items) {
										localStorage.setItem('outEnterCowshedData', JSON.stringify(JSON.stringify(items[0])));
										console.log(items[0])
										var str = items[0]["text"];
										if(outEnterCowshed == 1) {
											document.getElementById("outCowshedID").innerHTML = str;
											localStorage.setItem('ChooseACowshedData', JSON.stringify(items[0]["value"]));
											fromHouseID = items[0]["value"];
											Cattle();
										} else {
											document.getElementById("enterCowshedID").innerHTML = str;
											toHouseID = items[0]["value"];
											toHouseName = items[0]["text"];
										}
									});
								});
							})(mui, document);
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();　　　　　
							mui.alert("网络请求超时...");　　　　
						}　　
					}
				});
			}

			function Cattle() {
				var keys = JSON.parse(localStorage.getItem('key'));
				var ChooseACowshedData = JSON.parse(localStorage.getItem('ChooseACowshedData'));
				var map = {};
				if(ChooseACowshedData == "null") {
					map.houseID = '';
				} else {
					map.houseID = ChooseACowshedData;
				}
				map.key = keys;
				map.page = 1;
				map.size = 20;
				map.phoneType = "android";
				map.language = "zh";
				var jsonStr = JSON.stringify(map);
				console.log(jsonStr);
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "cowManagement",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							console.log(bb.data);
							var cowNumber = document.getElementById('cowNumber');
							wholeArr = bb.data;
							//绘制单个div
							function setDiv(item, i) {
								var div = '<div class="plzs-div" ><div class="ns-left"><input class="duoxuan" type="checkbox" name="Bike" value="' +
									i +
									'"/></div><div class="ns-right"><div class="ns-right-a">' +
									item.cowCode +
									'</div></div><div class="clear"></div></div>'
								return div
							}

							function getnoApplicationData() {
								var html = ''
								for(var i = 0; i < bb.data.length; i++) {
									html += setDiv(bb.data[i], i)
								}
								cowNumber.innerHTML = html
							}
							window.onload = getnoApplicationData()

						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();　
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();　　　　　
							mui.alert("网络请求超时...");　　　　
						}　　
					}
				});
			}
		</script>
	</body>

</html>